package spitfire.ksim.algorithm;

import java.util.ArrayList;

/**
 * FuzzyRule consists a series of 2-dimension points, which make up a curve by
 * connecting points one by one. It also stores a min and a max value related with
 * the curve. Their meaning may differ between different algorithm implementations
 * and not always indicates the min and max value of the curve.
 * 
 * @author Adam
 */
public class FuzzyRule {
	private final ArrayList<Double> xList = new ArrayList<Double>();
	private final ArrayList<Double> yList = new ArrayList<Double>();
	private double rMax;
	private double rMin;
	
	/**
	 * @return count of points in the rule.
	 */
	public int size() {
		if (xList.size() != yList.size()) {
			throw new RuntimeException("X,Y length not consistent");
		}
		return xList.size();
	}
	
	/**
	 * Add a point as the next point.
	 * @param x - x value of the point.
	 * @param y - y value of the point.
	 */
	public void add(Double x, Double y) {
		xList.add(x);
		yList.add(y);
	}
	
	/**
	 * Primitive version of {@link #add(Double, Double)}.
	 */
	public void add(double x, double y) {
		xList.add(x);
		yList.add(y);
	}

	/**
	 * Set rule max to the given value.
	 * @param rMax - rule max value.
	 */
	public void setrMax(double rMax) {
		this.rMax = rMax;
	}

	/**
	 * @return rule max value.
	 */
	public double getrMax() {
		return rMax;
	}

	/**
	 * Set rule min to the given value.
	 * @param rMin - rule min value.
	 */
	public void setrMin(double rMin) {
		this.rMin = rMin;
	}

	/**
	 * @return rule min value.
	 */
	public double getrMin() {
		return rMin;
	}
	
	/**
	 * @return list of x value of the points in original order.
	 */
	public ArrayList<Double> getxList() {
		return xList;
	}

	/**
	 * @return  list of y value of the points in original order.
	 */
	public ArrayList<Double> getyList() {
		return yList;
	}

	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("FuzzyRule [rMax=");
		builder.append(rMax);
		builder.append(", rMin=");
		builder.append(rMin);
		builder.append(", size=");
		builder.append(xList.size());
		builder.append("]");
		return builder.toString();
	}

	
}
